1708B - Difference of GCDs - CodeForces Solution


constructive algorithms math *1100

Please click on ads to support us..

Python Code:

import math
for i in range(int(input())):
    n,l,r = map(int,input().split())
    li = []
    if n==1:
        print('YES')
        print(r)
    else:
        for i in range(1,n+1):
            li.append(math.ceil(l/i)*i)
        if max(li)>r:
            print('NO')
        else:
            print('YES')
            print(*li)

C++ Code:

#include <bits/stdc++.h>
using namespace std;





/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted.
 *      ____________
 *     /            \
 *    /  /\      /\  \
 *   /  /  \    /  \  \
 *   \                /
 *    \     \___/    /
 *     \____________/
 */






#define f(i,j,k) for(long long i=j;i<k;i++)
#define cond(a) if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define test int t;cin>>t;while(t--)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
  return (a*b)/gcd(a,b);
}
ll PRO(ll a,ll b,ll MOD)
{
  return ((a%MOD)*(b%MOD)%MOD);
}
ll power(ll x, ll y, ll M)
{
  if (y == 0)
    return 1;
  ll p = power(x, y / 2, M) % M;
  p = (p * p) % M;
  return (y % 2 == 0) ? p : (x * p) % M;
}
ll modInverse(ll A, ll M)
{
  ll g = gcd(A, M);
  if (g != 1)
    return -1;
  else {
    return power(A, M - 2, M);
  }
}
bool isprime(ll n)
{

  for(ll i=2;i*i<=n;i++)
  {
    if(n%i==0)return false;
  }
  return true;
}


ll fact(ll n,ll m)
{
  if(n==0)
    return 1;
  ll res = 1;
  for (ll i=2;i<=n;i++){
    res=1ll * res*i;
    res%=m;
  }
  return res;
}
ll C(ll n, ll r)
{
  ll z=1;
  f(i,0,r)
  {
    z=z*(n-i)/(i+1);
  }
  return z;
}
const int N=500500;
bool prime[N + 1];
void SieveOfEratosthenes(int n)
{
  memset(prime, true, sizeof(prime));
    for (int p=2;p*p<=n;p++){
      if (prime[p] == true) {
        for (int i = p * p; i <= n; i += p)
          prime[i] = false;
      }
    }
}

int lowbit(int x)
{
  return x&(-x);
}









void solve()
{
  int n;
  cin>>n;
  ll l,r;
  cin>>l>>r;
  vector<ll>v;
  f(i,1,n+1)
  {
    ll k=i*((l-1)/i+1);
    if(k>r)
    {
      no;
      return;
    }
    v.pb(k);
  }
  yes;
  f(i,0,n)cout<<v[i]<<" ";
  cout<<endl;
}

int main()
{
  test
  {
    solve();
  }
  return 0;
}




























Comments

Submit
0 Comments
More Questions

Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array